package group.program.Controller;

import group.program.Service.DatabaseService;
import group.program.pojo.Dbstructure;
import group.program.pojo.trafficPojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("database")
@RestController
public class DatabaseController {
    @Autowired
    private DatabaseService databaseService;
    @PostMapping
    public Result AddDatabase(@RequestBody Dbstructure dbstructure){
        databaseService.addDatabase(dbstructure);
        return Result.success();
    }
    @DeleteMapping("/{did}")
    public Result RemoveDatabase(@PathVariable("did") Integer did){
        databaseService.removeDatabase(did);
        return Result.success();
    }
    @GetMapping
    public Result SelectDatabase(){
        List<Dbstructure> ls =databaseService.selectAll();
        return Result.success(ls);
    }

    @GetMapping("list")
    public Result SelectByName(String name){
        List<Dbstructure> ls =databaseService.selectByName(name);
        return Result.success(ls);
    }
}
